package {
	/* Our framework */
    import org.flixel.*;
	
	/* 
	 * Menu state, is the first screen that appears, 
	 * it's holds the options, and the trigger to start
	 * the adventure
	 */
    public class StateMenu extends FlxState	{
		
		/*
		 * Here we override the process to creation with our own ideas 
		 */
        override public function create():void {
			
			/* Main title: Last Space Defender */
            var _game_name:FlxText = new FlxText(0, 50, FlxG.width, "Last Space Defender");
            _game_name.setFormat(null, 42, 0xFFE01800, "center", 0xFFFC3C00);
            add(_game_name);
			
			/* This is the high score, we must connect him in a data base */
			var _max_record:FlxText = new FlxText(0, 100, FlxG.width, "HIGH SCORE: " + Main._high_score);
			_max_record.setFormat(null, 18, 0xFFFFFFFF, "center", 0XFF9999392);
			add(_max_record);				

			/* Instructions how to play */
            var _inst:FlxText = new FlxText(0, 250, FlxG.width,
                                "X Blast, C Shot, Direction Keys To Move");
            _inst.setFormat(null, 18, 0xFFFFFFFF, "center", 0xFF999999);
            add(_inst);
            
			/* Show how to start the game */
            var _keys:FlxText = new FlxText(0, 280, FlxG.width, "Press X, C To Start");
            _keys.setFormat(null, 18, 0xFFD9D0CF, "center", 0xFF999392);
            add(_keys);
            
			/* Setup and show the top panel */
            FlxG.panel.setup("", 0, "Last Space Defenfer", "", "");
            FlxG.mouse.show();
            FlxG.panel.show();

			/* Calls the parent */
            super.create();
        }

		/*
		 * Override the loop, this method is update every time
		 * and here we put our control, what we waiting for to 
		 * activate a lot of actions
		 */
        override public function update():void {
			
			/* If pressed C or X a little fadeout, and the new state is called */
			if(FlxG.keys.justPressed("C") || FlxG.keys.justPressed("X")) {
                FlxG.fade.start(0xff000000, 0.5, function():void {
                    FlxG.state = new StatePlay();});
			}
			
			/* Calls the parent */
            super.update();
        }
    }
}
